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

Remove Python2 only code #89

Open
kdheepak opened this issue Feb 9, 2024 · 5 comments
Open

Remove Python2 only code #89

kdheepak opened this issue Feb 9, 2024 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@kdheepak
Copy link
Contributor

kdheepak commented Feb 9, 2024

With Python2 support being dropped in #78, code associated with Python2 syntax can be upgraded to more idiomatic Python3 syntax.

This is a tracking issue for making these changes.

@kdheepak kdheepak added enhancement New feature or request good first issue Good for newcomers labels Feb 9, 2024
@kdheepak
Copy link
Contributor Author

kdheepak commented Feb 9, 2024

This try block can be simplified to remove the except block:

pyhelics/helics/capi.py

Lines 12 to 24 in 5516142

try:
from typing import Dict, List, Tuple, Union, Any, cast
JSONType = Union[
Dict[str, Any],
List[dict],
]
except ImportError:
JSONType = None
def cast(_, val):
return val

@kdheepak
Copy link
Contributor Author

kdheepak commented Feb 9, 2024

In Python2, f-string syntax was not supported, and Python 2 compatible s.format() needed to be used instead, e.g.

pyhelics/helics/capi.py

Lines 1070 to 1075 in 5516142

return """<helics.{class_name}(identifier = "{identifier}", address = "{address}") at {id}>""".format(
class_name=self.__class__.__name__,
identifier=identifier,
address=address,
id=hex(id(self)),
)

These can be changed to using f-string syntax:

f"""<helics.{self.__class__.__name__}(identifier = "{identifier}", address = "{address}") at {hex(id(self))}>"""

@kdheepak
Copy link
Contributor Author

kdheepak commented Feb 9, 2024

I believe you don't need these at the top of the file any more:

# -*- coding: utf-8 -*-

@kdheepak
Copy link
Contributor Author

kdheepak commented Feb 9, 2024

You can drop enum34 from the dependencies:

pyhelics/setup.py

Lines 558 to 559 in 5516142

if sys.version_info < (3, 4):
install_requires.append("enum34")

@nightlark
Copy link
Member

It looks like ruff implements pyupgrade checks/fixes, so maybe we could also run this to catch some syntax related updates: https://docs.astral.sh/ruff/rules/#pyupgrade-up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants