cut stringclasses 1
value | version stringclasses 10
values | idiom_id stringclasses 53
values | pep stringclasses 53
values | introduced_in stringclasses 11
values | form stringclasses 2
values | file stringclasses 887
values | code stringclasses 916
values | source stringclasses 1
value | origin stringlengths 15 17 | origin_revision stringclasses 10
values | license stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_01.py | lazy import json
lazy from json import dumps
| pydocs | pep-0810.rst:28 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_02.py | import sys
lazy import json
print('json' in sys.modules) # False - module not loaded yet
# First use triggers loading
result = json.dumps({"hello": "world"})
print('json' in sys.modules) # True - now loaded
| pydocs | pep-0810.rst:300 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_03.py | import sys
lazy from json import dumps, loads
print('json' in sys.modules) # False - module not loaded yet
# First use of 'dumps' triggers loading json and reifies ONLY 'dumps'
result = dumps({"hello": "world"})
print('json' in sys.modules) # True - module now loaded
# Accessing 'loads' now rei... | pydocs | pep-0810.rst:315 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_04.py | __lazy_modules__ = ["json"]
import json
print('json' in sys.modules) # False
result = json.dumps({"hello": "world"})
print('json' in sys.modules) # True
| pydocs | pep-0810.rst:348 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_05.py | # app.py - has a typo in the import
lazy from json import dumsp # Typo: should be 'dumps'
print("App started successfully")
print("Processing data...")
# Error occurs here on first use
result = dumsp({"key": "value"})
| pydocs | pep-0810.rst:439 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_06.py | # my_module.py
import sys
lazy import json
# Calling globals() does NOT trigger reification
g = globals()
print('json' in sys.modules) # False - still lazy
print(type(g['json'])) # <class 'LazyImport'>
# Accessing __dict__ also does NOT trigger reification
d = __dict__
print(type(d['json'])) # <class 'LazyImport'>... | pydocs | pep-0810.rst:495 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_07.py | lazy import json # IMPORT_NAME with flag set
| pydocs | pep-0810.rst:554 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_08.py | lazy from json import dumps # IMPORT_NAME + IMPORT_FROM
| pydocs | pep-0810.rst:564 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_09.py | lazy import json
x = json # Module-level access
| pydocs | pep-0810.rst:575 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_10.py | lazy import json
def use_json():
return json.dumps({}) # Function scope
| pydocs | pep-0810.rst:586 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_11.py | import sys
def exclude_side_effect_modules(importer, name, fromlist):
"""
Filter function to exclude modules with import-time side effects.
Args:
importer: Name of the module doing the import
name: Name of the module being imported
fromlist: Tuple of names being imported (for 'from... | pydocs | pep-0810.rst:658 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_12.py | # With eager import - error at import statement
import broken_module # ImportError raised here
# With lazy import - error deferred
lazy import broken_module
print("Import succeeded")
broken_module.foo() # ImportError raised here on use
| pydocs | pep-0810.rst:769 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_13.py | # Problematic: Plugin registers itself on import
# my_plugin.py
from plugin_registry import register_plugin
@register_plugin("MyPlugin")
class MyPlugin:
pass
# In main code:
lazy import my_plugin
# Plugin NOT registered yet - module not loaded!
# Better: Explicit discovery
# plugin_registry.py
def discover_plugi... | pydocs | pep-0810.rst:1004 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_14.py | # Before: Inline import (repeated overhead)
def process_data(data):
import json # Re-resolved on every call
return json.dumps(data)
# After: Lazy import at module level
lazy import json
def process_data(data):
return json.dumps(data) # Loaded once on first call
| pydocs | pep-0810.rst:1040 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_15.py | # heavy_module.py
print("Loading heavy_module") # This ALWAYS runs when module loads
class MyClass:
pass
class UnusedClass:
pass # Also gets defined, even though we don't import it
# app.py
lazy from heavy_module import MyClass
print("Import statement done") # heavy_module not loaded yet
obj = MyClass() ... | pydocs | pep-0810.rst:1163 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_16.py | lazy from collections.abc import Sequence, Mapping # No runtime cost
def process(items: Sequence[str]) -> Mapping[str, int]:
...
| pydocs | pep-0810.rst:1191 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | legacy | lazy-imports/legacy_01.py | from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Sequence, Mapping
def process(items: Sequence[str]) -> Mapping[str, int]:
...
| pydocs | pep-0810.rst:1200 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_17.py | # Works on Python 3.15+ as lazy, eager on older versions
__lazy_modules__ = ['expensive_module', 'expensive_module_2']
import expensive_module
from expensive_module_2 import MyClass
| pydocs | pep-0810.rst:1357 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_18.py | lazy from fake_typing import MyFakeType
def foo(x: MyFakeType):
pass
print(foo.__annotations__) # Triggers loading the fake_typing module
| pydocs | pep-0810.rst:1389 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_19.py | lazy import json
# Before any access
# json not in sys.modules
# Any of these trigger reification:
dumps_func = json.dumps
dumps_func = getattr(json, 'dumps')
# Now json is in sys.modules
| pydocs | pep-0810.rst:1403 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_20.py | # user_model.py
lazy import post_model
class User:
def get_posts(self):
# OK - post_model accessed inside function, not during import
return post_model.Post.get_by_user(self.name)
# post_model.py
lazy import user_model
class Post:
@staticmethod
def get_by_user(username):
return f"... | pydocs | pep-0810.rst:1426 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_21.py | # module_a.py
lazy import module_b
result = module_b.get_value() # Error! Accessing during import
def func():
return "A"
# module_b.py
lazy import module_a
result = module_a.func() # Circular dependency error here
def get_value():
return "B"
| pydocs | pep-0810.rst:1449 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_22.py | lazy import json
def use_json():
return json.dumps({"test": 1})
# First call triggers reification
use_json()
# After 2-3 calls, bytecode is specialized
use_json()
use_json()
| pydocs | pep-0810.rst:1481 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | modern | lazy-imports/modern_23.py | import sys
lazy import json
print('json' in sys.modules) # False
result = json.dumps({"key": "value"}) # First use
print('json' in sys.modules) # True
| pydocs | pep-0810.rst:1517 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | lazy-imports | 810 | 3.15 | legacy | lazy-imports/legacy_02.py | from typing import TYPE_CHECKING
if TYPE_CHECKING:
from foo import Bar # Could be automatically lazy
| pydocs | pep-0810.rst:1592 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | frozendict | 814 | 3.15 | modern | frozendict/modern_01.py | hash(frozendict(foo='bar')) # works
hash(frozendict(foo=['a', 'b', 'c'])) # error, list is not hashable
| pydocs | pep-0814.rst:111 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | frozendict | 814 | 3.15 | modern | frozendict/modern_02.py | a = frozendict(x=1, y=2)
b = frozendict(y=2, x=1)
hash(a) == hash(b)
a == b
| pydocs | pep-0814.rst:121 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | frozendict | 814 | 3.15 | modern | frozendict/modern_03.py | frozendict(x=1, y=2) == dict(x=1, y=2)
| pydocs | pep-0814.rst:130 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | frozendict | 814 | 3.15 | modern | frozendict/modern_04.py | frozendict(x=1) | frozendict(y=1)
frozendict(x=1) | dict(y=1)
| pydocs | pep-0814.rst:140 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | frozendict | 814 | 3.15 | modern | frozendict/modern_05.py | frozendict(x=1, y=2) | frozendict(y=5)
| pydocs | pep-0814.rst:147 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | frozendict | 814 | 3.15 | modern | frozendict/modern_06.py | d = frozendict(x=1)
copy = d
d |= frozendict(y=2)
d
copy # left unchanged
| pydocs | pep-0814.rst:153 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | frozendict | 814 | 3.15 | modern | frozendict/modern_07.py | import copy
d = frozendict(mutable=[])
shallow_copy = d.copy()
deep_copy = copy.deepcopy(d)
d['mutable'].append('modified')
d
shallow_copy # modified!
deep_copy # unchanged
| pydocs | pep-0814.rst:174 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
train | 3.15 | frozendict | 814 | 3.15 | modern | frozendict/modern_08.py | m: frozendict[str, int] = frozendict(x=1)
| pydocs | pep-0814.rst:192 | e449c7e446faec3ecf953e83fbe677b771bf5d7c | CC0-1.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.