Skip to content

Commit

Permalink
Ignore pre-existing type warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jtwang committed Dec 13, 2023
1 parent 0909829 commit 40fbe01
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
32 changes: 16 additions & 16 deletions bravado_core/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,62 +141,62 @@ def wrapper(validatable_primitive):
BASE64_BYTE_FORMAT = SwaggerFormat(
format='byte',
# Note: In Python 3, this requires a bytes-like object as input
to_wire=lambda b: six.ensure_str(base64.b64encode(b), encoding=str('ascii')),
to_python=lambda s: base64.b64decode(six.ensure_binary(s, encoding=str('ascii'))),
to_wire=lambda b: six.ensure_str(base64.b64encode(b), encoding=str('ascii')), # type: ignore
to_python=lambda s: base64.b64decode(six.ensure_binary(s, encoding=str('ascii'))), # type: ignore
validate=NO_OP, # jsonschema validates string
description='Converts [wire]string:byte <=> python bytes',
)

DEFAULT_FORMATS = {
'byte': SwaggerFormat(
format='byte',
to_wire=lambda b: b if isinstance(b, str) else str(b),
to_python=lambda s: s if isinstance(s, str) else str(s),
to_wire=lambda b: b if isinstance(b, str) else str(b), # type: ignore
to_python=lambda s: s if isinstance(s, str) else str(s), # type: ignore
validate=NO_OP, # jsonschema validates string
description='Converts [wire]string:byte <=> python byte',
),
'date': SwaggerFormat(
format='date',
to_wire=lambda d: d.isoformat(),
to_python=lambda d: dateutil.parser.parse(d).date(),
to_wire=lambda d: d.isoformat(), # type: ignore
to_python=lambda d: dateutil.parser.parse(d).date(), # type: ignore
validate=NO_OP, # jsonschema validates date
description='Converts [wire]string:date <=> python datetime.date',
),
# Python has no double. float is C's double in CPython
'double': SwaggerFormat(
format='double',
to_wire=lambda d: d if isinstance(d, float) else float(d),
to_python=lambda d: d if isinstance(d, float) else float(d),
to_wire=lambda d: d if isinstance(d, float) else float(d), # type: ignore
to_python=lambda d: d if isinstance(d, float) else float(d), # type: ignore
validate=NO_OP, # jsonschema validates number
description='Converts [wire]number:double <=> python float',
),
'date-time': SwaggerFormat(
format='date-time',
to_wire=lambda dt: (dt if dt.tzinfo else pytz.utc.localize(dt)).isoformat(),
to_python=lambda dt: dateutil.parser.parse(dt),
to_wire=lambda dt: (dt if dt.tzinfo else pytz.utc.localize(dt)).isoformat(), # type: ignore
to_python=lambda dt: dateutil.parser.parse(dt), # type: ignore
validate=NO_OP, # jsonschema validates date-time
description=(
'Converts string:date-time <=> python datetime.datetime'
),
),
'float': SwaggerFormat(
format='float',
to_wire=lambda f: f if isinstance(f, float) else float(f),
to_python=lambda f: f if isinstance(f, float) else float(f),
to_wire=lambda f: f if isinstance(f, float) else float(f), # type: ignore
to_python=lambda f: f if isinstance(f, float) else float(f), # type: ignore
validate=NO_OP, # jsonschema validates number
description='Converts [wire]number:float <=> python float',
),
'int32': SwaggerFormat(
format='int32',
to_wire=lambda i: i if isinstance(i, int) else int(i),
to_python=lambda i: i if isinstance(i, int) else int(i),
to_wire=lambda i: i if isinstance(i, int) else int(i), # type: ignore
to_python=lambda i: i if isinstance(i, int) else int(i), # type: ignore
validate=NO_OP, # jsonschema validates integer
description='Converts [wire]integer:int32 <=> python int',
),
'int64': SwaggerFormat(
format='int64',
to_wire=lambda i: i if isinstance(i, long) else long(i),
to_python=lambda i: i if isinstance(i, long) else long(i),
to_wire=lambda i: i if isinstance(i, long) else long(i), # type: ignore
to_python=lambda i: i if isinstance(i, long) else long(i), # type: ignore
validate=NO_OP, # jsonschema validates integer
description='Converts [wire]integer:int64 <=> python long',
),
Expand Down
4 changes: 2 additions & 2 deletions tests/swagger20_validator/format_validator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def validate_dummy(dummy_string):

DummyFormat = SwaggerFormat(
format="dummy",
to_wire=lambda x: x,
to_python=lambda x: x,
to_wire=lambda x: x, # type: ignore
to_python=lambda x: x, # type: ignore
validate=validate_dummy,
description="dummy format",
)
Expand Down
4 changes: 2 additions & 2 deletions tests/validate/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def validate_email_address(email_address):

email_address_format = SwaggerFormat(
format='email_address',
to_wire=lambda x: x,
to_python=lambda x: x,
to_wire=lambda x: x, # type: ignore
to_python=lambda x: x, # type: ignore
validate=validate_email_address,
description='blah',
)

0 comments on commit 40fbe01

Please sign in to comment.