Skip to content

update to coverage_attribute feature #966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ fn generate_self_schema() {

fn main() {
pyo3_build_config::use_pyo3_cfgs();
if let Some(true) = version_check::supports_feature("no_coverage") {
println!("cargo:rustc-cfg=has_no_coverage");
if let Some(true) = version_check::supports_feature("coverage_attribute") {
println!("cargo:rustc-cfg=has_coverage_attribute");
}
generate_self_schema();
println!("cargo:rustc-env=PROFILE={}", std::env::var("PROFILE").unwrap());
Expand Down
2 changes: 1 addition & 1 deletion src/build_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl fmt::Display for SchemaError {
}

impl Error for SchemaError {
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
Expand Down
30 changes: 15 additions & 15 deletions src/input/input_abstract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
}
}
fn strict_str(&'a self) -> ValResult<EitherString<'a>>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_str(&'a self) -> ValResult<EitherString<'a>> {
self.strict_str()
}
Expand All @@ -93,7 +93,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
}
}
fn strict_bytes(&'a self) -> ValResult<EitherBytes<'a>>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_bytes(&'a self) -> ValResult<EitherBytes<'a>> {
self.strict_bytes()
}
Expand All @@ -106,7 +106,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
}
}
fn strict_bool(&self) -> ValResult<bool>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_bool(&self) -> ValResult<bool> {
self.strict_bool()
}
Expand All @@ -119,7 +119,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
}
}
fn strict_int(&'a self) -> ValResult<EitherInt<'a>>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_int(&'a self) -> ValResult<EitherInt<'a>> {
self.strict_int()
}
Expand Down Expand Up @@ -147,7 +147,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
}
fn ultra_strict_float(&'a self) -> ValResult<EitherFloat<'a>>;
fn strict_float(&'a self) -> ValResult<EitherFloat<'a>>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_float(&'a self) -> ValResult<EitherFloat<'a>> {
self.strict_float()
}
Expand All @@ -160,7 +160,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
}
}
fn strict_decimal(&'a self, py: Python<'a>) -> ValResult<&'a PyAny>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_decimal(&'a self, py: Python<'a>) -> ValResult<&'a PyAny> {
self.strict_decimal(py)
}
Expand All @@ -173,7 +173,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
}
}
fn strict_dict(&'a self) -> ValResult<GenericMapping<'a>>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_dict(&'a self) -> ValResult<GenericMapping<'a>> {
self.strict_dict()
}
Expand All @@ -190,7 +190,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
}
}
fn strict_list(&'a self) -> ValResult<GenericIterable<'a>>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_list(&'a self) -> ValResult<GenericIterable<'a>> {
self.strict_list()
}
Expand All @@ -203,7 +203,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
}
}
fn strict_tuple(&'a self) -> ValResult<GenericIterable<'a>>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_tuple(&'a self) -> ValResult<GenericIterable<'a>> {
self.strict_tuple()
}
Expand All @@ -216,7 +216,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
}
}
fn strict_set(&'a self) -> ValResult<GenericIterable<'a>>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_set(&'a self) -> ValResult<GenericIterable<'a>> {
self.strict_set()
}
Expand All @@ -229,7 +229,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
}
}
fn strict_frozenset(&'a self) -> ValResult<GenericIterable<'a>>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_frozenset(&'a self) -> ValResult<GenericIterable<'a>> {
self.strict_frozenset()
}
Expand All @@ -246,7 +246,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
}
}
fn strict_date(&self) -> ValResult<EitherDate>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_date(&self) -> ValResult<EitherDate> {
self.strict_date()
}
Expand All @@ -266,7 +266,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
&self,
microseconds_overflow_behavior: speedate::MicrosecondsPrecisionOverflowBehavior,
) -> ValResult<EitherTime>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_time(
&self,
microseconds_overflow_behavior: speedate::MicrosecondsPrecisionOverflowBehavior,
Expand All @@ -289,7 +289,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
&self,
microseconds_overflow_behavior: speedate::MicrosecondsPrecisionOverflowBehavior,
) -> ValResult<EitherDateTime>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_datetime(
&self,
microseconds_overflow_behavior: speedate::MicrosecondsPrecisionOverflowBehavior,
Expand All @@ -312,7 +312,7 @@ pub trait Input<'a>: fmt::Debug + ToPyObject {
&self,
microseconds_overflow_behavior: speedate::MicrosecondsPrecisionOverflowBehavior,
) -> ValResult<EitherTimedelta>;
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn lax_timedelta(
&self,
microseconds_overflow_behavior: speedate::MicrosecondsPrecisionOverflowBehavior,
Expand Down
56 changes: 28 additions & 28 deletions src/input/input_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use super::{

impl<'a> Input<'a> for JsonInput {
/// This is required by since JSON object keys are always strings, I don't think it can be called
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn as_loc_item(&self) -> LocItem {
match self {
JsonInput::Int(i) => (*i).into(),
Expand Down Expand Up @@ -102,7 +102,7 @@ impl<'a> Input<'a> for JsonInput {
_ => Err(ValError::new(ErrorTypeDefaults::BytesType, self)),
}
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_bytes(&'a self) -> ValResult<EitherBytes<'a>> {
self.validate_bytes(false)
}
Expand Down Expand Up @@ -196,7 +196,7 @@ impl<'a> Input<'a> for JsonInput {
_ => Err(ValError::new(ErrorTypeDefaults::DictType, self)),
}
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_dict(&'a self) -> ValResult<GenericMapping<'a>> {
self.validate_dict(false)
}
Expand All @@ -207,7 +207,7 @@ impl<'a> Input<'a> for JsonInput {
_ => Err(ValError::new(ErrorTypeDefaults::ListType, self)),
}
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_list(&'a self) -> ValResult<GenericIterable<'a>> {
self.validate_list(false)
}
Expand All @@ -219,7 +219,7 @@ impl<'a> Input<'a> for JsonInput {
_ => Err(ValError::new(ErrorTypeDefaults::TupleType, self)),
}
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_tuple(&'a self) -> ValResult<GenericIterable<'a>> {
self.validate_tuple(false)
}
Expand All @@ -231,7 +231,7 @@ impl<'a> Input<'a> for JsonInput {
_ => Err(ValError::new(ErrorTypeDefaults::SetType, self)),
}
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_set(&'a self) -> ValResult<GenericIterable<'a>> {
self.validate_set(false)
}
Expand All @@ -243,7 +243,7 @@ impl<'a> Input<'a> for JsonInput {
_ => Err(ValError::new(ErrorTypeDefaults::FrozenSetType, self)),
}
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_frozenset(&'a self) -> ValResult<GenericIterable<'a>> {
self.validate_frozenset(false)
}
Expand Down Expand Up @@ -278,7 +278,7 @@ impl<'a> Input<'a> for JsonInput {
}
// NO custom `lax_date` implementation, if strict_date fails, the validator will fallback to lax_datetime
// then check there's no remainder
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_date(&self) -> ValResult<EitherDate> {
self.validate_date(false)
}
Expand Down Expand Up @@ -365,7 +365,7 @@ impl<'a> Input<'a> for String {
InputValue::String(self)
}

#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn is_none(&self) -> bool {
false
}
Expand All @@ -374,12 +374,12 @@ impl<'a> Input<'a> for String {
None
}

#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn validate_args(&'a self) -> ValResult<'a, GenericArguments<'a>> {
Err(ValError::new(ErrorTypeDefaults::ArgumentsType, self))
}

#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn validate_dataclass_args(&'a self, class_name: &str) -> ValResult<'a, GenericArguments<'a>> {
let class_name = class_name.to_string();
Err(ValError::new(
Expand All @@ -405,7 +405,7 @@ impl<'a> Input<'a> for String {
fn validate_bytes(&'a self, _strict: bool) -> ValResult<EitherBytes<'a>> {
Ok(self.as_bytes().into())
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_bytes(&'a self) -> ValResult<EitherBytes<'a>> {
self.validate_bytes(false)
}
Expand All @@ -427,11 +427,11 @@ impl<'a> Input<'a> for String {
}
}

#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn ultra_strict_float(&'a self) -> ValResult<EitherFloat<'a>> {
self.strict_float()
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_float(&'a self) -> ValResult<EitherFloat<'a>> {
Err(ValError::new(ErrorTypeDefaults::FloatType, self))
}
Expand All @@ -443,47 +443,47 @@ impl<'a> Input<'a> for String {
create_decimal(self.to_object(py).into_ref(py), self, py)
}

#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn validate_dict(&'a self, _strict: bool) -> ValResult<GenericMapping<'a>> {
Err(ValError::new(ErrorTypeDefaults::DictType, self))
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_dict(&'a self) -> ValResult<GenericMapping<'a>> {
self.validate_dict(false)
}

#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn validate_list(&'a self, _strict: bool) -> ValResult<GenericIterable<'a>> {
Err(ValError::new(ErrorTypeDefaults::ListType, self))
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_list(&'a self) -> ValResult<GenericIterable<'a>> {
self.validate_list(false)
}

#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn validate_tuple(&'a self, _strict: bool) -> ValResult<GenericIterable<'a>> {
Err(ValError::new(ErrorTypeDefaults::TupleType, self))
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_tuple(&'a self) -> ValResult<GenericIterable<'a>> {
self.validate_tuple(false)
}

#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn validate_set(&'a self, _strict: bool) -> ValResult<GenericIterable<'a>> {
Err(ValError::new(ErrorTypeDefaults::SetType, self))
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_set(&'a self) -> ValResult<GenericIterable<'a>> {
self.validate_set(false)
}

#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn validate_frozenset(&'a self, _strict: bool) -> ValResult<GenericIterable<'a>> {
Err(ValError::new(ErrorTypeDefaults::FrozenSetType, self))
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_frozenset(&'a self) -> ValResult<GenericIterable<'a>> {
self.validate_frozenset(false)
}
Expand All @@ -499,7 +499,7 @@ impl<'a> Input<'a> for String {
fn validate_date(&self, _strict: bool) -> ValResult<EitherDate> {
bytes_as_date(self, self.as_bytes())
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_date(&self) -> ValResult<EitherDate> {
self.validate_date(false)
}
Expand All @@ -511,7 +511,7 @@ impl<'a> Input<'a> for String {
) -> ValResult<EitherTime> {
bytes_as_time(self, self.as_bytes(), microseconds_overflow_behavior)
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_time(
&self,
microseconds_overflow_behavior: speedate::MicrosecondsPrecisionOverflowBehavior,
Expand All @@ -526,7 +526,7 @@ impl<'a> Input<'a> for String {
) -> ValResult<EitherDateTime> {
bytes_as_datetime(self, self.as_bytes(), microseconds_overflow_behavior)
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_datetime(
&self,
microseconds_overflow_behavior: speedate::MicrosecondsPrecisionOverflowBehavior,
Expand All @@ -541,7 +541,7 @@ impl<'a> Input<'a> for String {
) -> ValResult<EitherTimedelta> {
bytes_as_timedelta(self, self.as_bytes(), microseconds_overflow_behavior)
}
#[cfg_attr(has_no_coverage, no_coverage)]
#[cfg_attr(has_coverage_attribute, coverage(off))]
fn strict_timedelta(
&self,
microseconds_overflow_behavior: speedate::MicrosecondsPrecisionOverflowBehavior,
Expand Down
Loading