Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[mypyc] Document more unsupported features & update supported features#15524

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JukkaL merged 2 commits intopython:masterfromichard26:better-mypyc-docs
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
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
NextNext commit
[mypyc] Document more unsupported features & update supported features
  • Loading branch information
@ichard26
ichard26 committedJun 26, 2023
commite60f8abb241a3ebf9c725524df0f835189ea59a9
38 changes: 26 additions & 12 deletionsmypyc/doc/differences_from_python.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -268,19 +268,27 @@ used in compiled code, or there are some limitations. You can
partially work around some of these limitations by running your code
in interpreted mode.

Operator overloading
********************
Nested classes
**************

Native classescan only use these dunder methods to override operators:
Nested classesare not supported.

* ``__eq__``
* ``__ne__``
* ``__getitem__``
* ``__setitem__``
Conditional functions or classes
********************************

.. note::
Function and classes definitions guarded by an if-statement are not supported.

Dunder methods
**************

This limitation will be lifted in the future.
Native classes **cannot** use these dunders. If defined, they will not
work as expected.

* ``__del__``
* ``__index__``
* ``__getattr__``, ``__getattribute__``
* ``__setattr__``
* ``__delattr__``

Generator expressions
*********************
Expand All@@ -299,10 +307,16 @@ Descriptors
Native classes can't contain arbitrary descriptors. Properties, static
methods and class methods are supported.

Stack introspection
*******************
Introspection
*************

Various methods of introspection may break by using mypyc. Here's an
non-exhaustive list of what won't work:

Frames of compiled functions can't be inspected using ``inspect``.
- Instance ``__annotations__`` is usually not kept
- Frames of compiled functions can't be inspected using ``inspect``
- Compiled methods aren't considered methods by ``inspect.ismethod``
- ``inspect.signature`` chokes on compiled functions

Profiling hooks and tracing
***************************
Expand Down
12 changes: 10 additions & 2 deletionsmypyc/doc/native_classes.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,6 +63,8 @@ classes:
* ``IndexError``
* ``LookupError``
* ``UserWarning``
* ``typing.NamedTuple``
* ``enum.Enum``

By default, a non-native class can't inherit a native class, and you
can't inherit from a native class outside the compilation unit that
Expand DownExpand Up@@ -104,6 +106,11 @@ through an instance. Example::
print(o.cv) # OK (2)
o.cv = 3 # Error!

.. tip::

Constant class variables can be declared using ``typing.Final`` or
``typing.Final[<type>]``.

Generic native classes
----------------------

Expand DownExpand Up@@ -150,9 +157,10 @@ decorators can be used with native classes, however:
* ``mypy_extensions.trait`` (for defining :ref:`trait types <trait-types>`)
* ``mypy_extensions.mypyc_attr`` (see :ref:`above <inheritance>`)
* ``dataclasses.dataclass``
* ``@attr.s(auto_attribs=True)``

Dataclasses have partial native support, and they aren't as efficient
as pure native classes.
Dataclassesand attrs classeshave partial native support, and they aren't as
efficientas pure native classes.

.. note::

Expand Down
4 changes: 2 additions & 2 deletionsmypyc/doc/using_type_annotations.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -194,8 +194,8 @@ Traits have some special properties:
* You shouldn't create instances of traits (though mypyc does not
prevent it yet).

* Traits can subclass other traits, butthey can't subclass non-trait
classes (other than ``object``).
* Traits can subclass other traits or native classes, butthe MRO must be
linear (just like with native classes).

* Accessing methods or attributes through a trait type is somewhat
less efficient than through a native class type, but this is much
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp