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

Overload fast_plain_mtext to different return types depending on split= #1172

Conversation

bswck-hai
Copy link
Contributor

@bswck-hai bswck-hai commented Sep 23, 2024

  • Type checked the code.

@bswck-hai
Copy link
Contributor Author

@mozman Please review.

@mozman
Copy link
Owner

mozman commented Sep 29, 2024

Thanks for your contribution, but currently I integrate only bug fixes for more information see my latest posting #1175.

Union,
Optional,
Callable,
NamedTuple,
Any,
overload,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has to be imported from typing_extensions , not available in Python 3.9 (requires 3.11)

Copy link
Contributor Author

@bswck-hai bswck-hai Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typing.overload is part of PEP 484 and has always been in the typing module.

@@ -9,11 +9,13 @@
Iterable,
Iterator,
TYPE_CHECKING,
Literal,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from typing_extensions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Literal has been there since Python 3.8, ezdxf supports 3.9+.

# pylint: disable-next=too-many-branches
def fast_plain_mtext(text: str, split=False) -> Union[list[str], str]:
def fast_plain_mtext(text: str, split: bool = False) -> Union[list[str], str]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't add bool for such cases, type inference by False and True, shorter signatures are better, therefore return list[str]|str .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue that shorter signatures aren't better when compared against actually accurate signatures.
Type inference from False is Any in mypy (not mentioning it erroring in strict mode).

Copy link
Contributor Author

@bswck-hai bswck-hai Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

therefore return list[str]|str

Migrating to PEP 604 is a topic for a different PR.

@mozman
Copy link
Owner

mozman commented Nov 5, 2024

Thank you, you are right on all points, but I'm afraid I don't want to deal with this or any future contributions from you.

@mozman mozman closed this Nov 5, 2024
@bswck-hai
Copy link
Contributor Author

bswck-hai commented Nov 5, 2024 via email

@bswck-hai
Copy link
Contributor Author

@mozman could you please reopen this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants