Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Oct 15, 2024
1 parent d5ddb16 commit 3b26e36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Lib/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1620,13 +1620,13 @@ def annotate_method(format):
for ann, t in annotations.items()
}

from typing import Any, _convert_to_source
from typing import Any
ann_dict = {
ann: Any if t is _ANY_MARKER else t
for ann, t in annotations.items()
}
if format == annotationlib.Format.SOURCE:
return _convert_to_source(ann_dict)
if format == annotationlib.Format.STRING:
return annotationlib.annotations_to_string(ann_dict)
return ann_dict

# Update 'ns' with the user-supplied namespace plus our calculated values.
Expand Down
11 changes: 6 additions & 5 deletions Lib/test/test_dataclasses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import types
import weakref
import traceback
import sys
import unittest
from unittest.mock import Mock
from typing import ClassVar, Any, List, Union, Tuple, Dict, Generic, TypeVar, Optional, Protocol, DefaultDict
Expand Down Expand Up @@ -4247,16 +4248,16 @@ def test_no_types_get_annotations(self):
)
self.assertEqual(
annotationlib.get_annotations(
C, format=annotationlib.Format.SOURCE),
C, format=annotationlib.Format.STRING),
{'x': 'typing.Any', 'y': 'int', 'z': 'typing.Any'},
)

def test_no_types_no_typing_import(self):
import sys

C = make_dataclass('C', ['x', ('y', int)])

with import_helper.CleanImport('typing'):
self.assertNotIn('typing', sys.modules)
C = make_dataclass('C', ['x', ('y', int)])

self.assertNotIn('typing', sys.modules)
self.assertEqual(
annotationlib.get_annotations(
C, format=annotationlib.Format.FORWARDREF),
Expand Down

0 comments on commit 3b26e36

Please sign in to comment.