From fcced9aa649c4b67bc9440e1bcf94b4ca6d44f11 Mon Sep 17 00:00:00 2001 From: sbasan Date: Thu, 25 Apr 2024 14:55:33 +0200 Subject: [PATCH] fix: pre commit issues --- .pre-commit-config.yaml | 2 +- endpoints-md.py | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3b20bd13..2bfce72e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: # Code analysis (only checks staged files) - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.2.0 + rev: v1.9.0 hooks: - id: mypy name: mypy diff --git a/endpoints-md.py b/endpoints-md.py index 5aeb2c9d..b8174a9b 100644 --- a/endpoints-md.py +++ b/endpoints-md.py @@ -12,6 +12,7 @@ from urllib.request import pathname2url from packaging.specifiers import SpecifierSet # type: ignore +from typing_extensions import get_original_bases from catalystwan import __package__ from catalystwan.endpoints import BASE_PATH, APIEndpointRequestMeta, TypeSpecifier, request, versions, view @@ -110,13 +111,20 @@ def from_type_specifier(typespec: TypeSpecifier) -> CompositeTypeLink: if payloadtype.__module__ == "builtins": return CompositeTypeLink.text_only(payloadtype.__name__) elif sourcefile := getsourcefile(payloadtype): - print(payloadtype) - return CompositeTypeLink( - link_text=payloadtype.__name__, - sourcefile=create_sourcefile_link(sourcefile), - lineno=getsourcelines(payloadtype)[1], - origin=generate_origin_string(typespec), - ) + try: + lineno = getsourcelines(payloadtype)[1] + link_text = payloadtype.__name__ + except OSError: + base, *_ = get_original_bases(payloadtype) + lineno = getsourcelines(base)[1] + link_text = base.__name__ + finally: + return CompositeTypeLink( + link_text=link_text, + sourcefile=create_sourcefile_link(sourcefile), + lineno=lineno, + origin=generate_origin_string(typespec), + ) return CompositeTypeLink.text_only("") def md(self) -> str: