Skip to content
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

drop basestring hack, Python 2 is no more #183

Merged
merged 1 commit into from
Nov 19, 2024
Merged
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
9 changes: 2 additions & 7 deletions apypie/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
from apypie.param import Param
from apypie.exceptions import MissingArgumentsError, InvalidArgumentTypesError

try:
basestring # type: ignore[used-before-def] # pylint: disable=used-before-assignment
except NameError: # Python 3 has no basestring
basestring = str # pylint: disable=invalid-name,redefined-builtin

if TYPE_CHECKING:
from apypie.api import Api # pylint: disable=cyclic-import,unused-import # noqa: F401

Expand Down Expand Up @@ -159,7 +154,7 @@ def _validate(self, params, values, data=None, files=None, path=None): # pylint
self._validate(param_description.params, item, path=self._add_to_path(path, [param_description.name, str(num)]))
elif param_description.expected_type == 'hash':
self._validate(param_description.params, value, path=self._add_to_path(path, [param_description.name]))
if (param_description.expected_type == 'numeric' and isinstance(value, basestring)):
if (param_description.expected_type == 'numeric' and isinstance(value, str)):
try:
value = int(value)
except ValueError:
Expand All @@ -171,7 +166,7 @@ def _validate(self, params, values, data=None, files=None, path=None): # pylint
if (value is not None
and ((param_description.expected_type == 'boolean' and not isinstance(value, bool) and not (isinstance(value, int) and value in [0, 1]))
or (param_description.expected_type == 'numeric' and not isinstance(value, int))
or (param_description.expected_type == 'string' and not isinstance(value, (basestring, int))))):
or (param_description.expected_type == 'string' and not isinstance(value, (str, int))))):
raise ValueError("{} ({}): {}".format(param, value, param_description.validator))

@staticmethod
Expand Down