Loaders¤
Main API¤
load ¤
load(
objspec: str | Path | None = None,
/,
*,
submodules: bool = True,
try_relative_path: bool = True,
extensions: Extensions | None = None,
search_paths: Sequence[str | Path] | None = None,
docstring_parser: DocstringStyle | Parser | None = None,
docstring_options: DocstringOptions | None = None,
lines_collection: LinesCollection | None = None,
modules_collection: ModulesCollection | None = None,
allow_inspection: bool = True,
force_inspection: bool = False,
store_source: bool = True,
find_stubs_package: bool = False,
resolve_aliases: bool = False,
resolve_external: bool | None = None,
resolve_implicit: bool = False,
) -> Object | Alias
Load and return a Griffe object.
In Griffe's context, loading means:
- searching for a package, and finding it on the file system or as a builtin module (see the
ModuleFinderclass for more information) - extracting information from each of its (sub)modules, by either parsing the source code (see the
visitfunction) or inspecting the module at runtime (see theinspectfunction)
The extracted information is stored in a collection of modules, which can be queried later. Each collected module is a tree of objects, representing the structure of the module. See the Module, Class, Function, Attribute, and TypeAlias classes for more information.
The main class used to load modules is GriffeLoader. Convenience functions like this one and load_git are also available.
Example
import griffe
module = griffe.load(...)
This is a shortcut for:
from griffe import GriffeLoader
loader = GriffeLoader(...)
module = loader.load(...)
See the documentation for the loader: GriffeLoader.
Parameters:
-
(objspec¤str | Path | None, default:None) –The Python path of an object, or file path to a module.
-
(submodules¤bool, default:True) –Whether to recurse on the submodules. This parameter only makes sense when loading a package (top-level module).
-
(try_relative_path¤bool, default:True) –Whether to try finding the module as a relative path.
-
(extensions¤Extensions | None, default:None) –The extensions to use.
-
(search_paths¤Sequence[str | Path] | None, default:None) –The paths to search into.
-
(docstring_parser¤DocstringStyle | Parser | None, default:None) –The docstring parser to use. By default, no parsing is done.
-
(docstring_options¤DocstringOptions | None, default:None) –Docstring parsing options.
-
(lines_collection¤LinesCollection | None, default:None) –A collection of source code lines.
-
(modules_collection¤ModulesCollection | None, default:None) –A collection of modules.
-
(allow_inspection¤bool, default:True) –Whether to allow inspecting modules when visiting them is not possible.
-
(force_inspection¤bool, default:False) –Whether to force using dynamic analysis when loading data.
-
(store_source¤bool, default:True) –Whether to store code source in the lines collection.
-
(find_stubs_package¤bool, default:False) –Whether to search for stubs-only package. If both the package and its stubs are found, they'll be merged together. If only the stubs are found, they'll be used as the package itself.
-
(resolve_aliases¤bool, default:False) –Whether to resolve aliases.
-
(resolve_external¤bool | None, default:None) –Whether to try to load unspecified modules to resolve aliases. Default value (
None) means to load external modules only if they are the private sibling or the origin module (for example whenastimports from_ast). -
(resolve_implicit¤bool, default:False) –When false, only try to resolve an alias if it is explicitly exported.
Returns:
- Getting started Introduction Python library
- Guide User guide Manipulating APIs
- Reference
Source code in src/griffe/_internal/loader.py
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 | |
load_git ¤
load_git(
objspec: str | Path | None = None,
/,
*,
ref: str = "HEAD",
repo: str | Path = ".",
submodules: bool = True,
extensions: Extensions | None = None,
search_paths: Sequence[str | Path] | None = None,
docstring_parser: DocstringStyle | Parser | None = None,
docstring_options: DocstringOptions | None = None,
lines_collection: LinesCollection | None = None,
modules_collection: ModulesCollection | None = None,
allow_inspection: bool = True,
force_inspection: bool = False,
find_stubs_package: bool = False,
resolve_aliases: bool = False,
resolve_external: bool | None = None,
resolve_implicit: bool = False,
) -> Object | Alias
Load and return a module from a specific Git reference.
This function will create a temporary git worktree at the requested reference before loading module with griffe.load.
This function requires that the git executable is installed.
Examples:
from griffe import load_git
old_api = load_git("my_module", ref="v0.1.0", repo="path/to/repo")
Parameters:
-
(objspec¤str | Path | None, default:None) –The Python path of an object, or file path to a module.
-
(ref¤str, default:'HEAD') –A Git reference such as a commit, tag or branch.
-
(repo¤str | Path, default:'.') –Path to the repository (i.e. the directory containing the
.gitdirectory) -
(submodules¤bool, default:True) –Whether to recurse on the submodules. This parameter only makes sense when loading a package (top-level module).
-
(extensions¤Extensions | None, default:None) –The extensions to use.
-
(search_paths¤Sequence[str | Path] | None, default:None) –The paths to search into (relative to the repository root).
-
(docstring_parser¤DocstringStyle | Parser | None, default:None) –The docstring parser to use. By default, no parsing is done.
-
(docstring_options¤DocstringOptions | None, default:None) –Docstring parsing options.
-
(lines_collection¤LinesCollection | None, default:None) –A collection of source code lines.
-
(modules_collection¤ModulesCollection | None, default:None) –A collection of modules.
-
(allow_inspection¤bool, default:True) –Whether to allow inspecting modules when visiting them is not possible.
-
(force_inspection¤bool, default:False) –Whether to force using dynamic analysis when loading data.
-
(find_stubs_package¤bool, default:False) –Whether to search for stubs-only package. If both the package and its stubs are found, they'll be merged together. If only the stubs are found, they'll be used as the package itself.
-
(resolve_aliases¤bool, default:False) –Whether to resolve aliases.
-
(resolve_external¤bool | None, default:None) –Whether to try to load unspecified modules to resolve aliases. Default value (
None) means to load external modules only if they are the private sibling or the origin module (for example whenastimports from_ast). -
(resolve_implicit¤bool, default:False) –When false, only try to resolve an alias if it is explicitly exported.
Returns:
Source code in src/griffe/_internal/loader.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 | |
load_pypi ¤
load_pypi(
package: str,
distribution: str,
version_spec: str,
*,
submodules: bool = True,
extensions: Extensions | None = None,
search_paths: Sequence[str | Path] | None = None,
docstring_parser: DocstringStyle | Parser | None = None,
docstring_options: DocstringOptions | None = None,
lines_collection: LinesCollection | None = None,
modules_collection: ModulesCollection | None = None,
allow_inspection: bool = True,
force_inspection: bool = False,
find_stubs_package: bool = False,
resolve_aliases: bool = False,
resolve_external: bool | None = None,
resolve_implicit: bool = False,
) -> Object | Alias
Load and return a module from a specific package version downloaded using pip.
Parameters:
-
(package¤str) –The package import name.
-
(distribution¤str) –The distribution name.
-
(version_spec¤str) –The version specifier to use when installing with pip.
-
(submodules¤bool, default:True) –Whether to recurse on the submodules. This parameter only makes sense when loading a package (top-level module).
-
(extensions¤Extensions | None, default:None) –The extensions to use.
-
(search_paths¤Sequence[str | Path] | None, default:None) –The paths to search into (relative to the repository root).
-
(docstring_parser¤DocstringStyle | Parser | None, default:None) –The docstring parser to use. By default, no parsing is done.
-
(docstring_options¤DocstringOptions | None, default:None) –Docstring parsing options.
-
(lines_collection¤LinesCollection | None, default:None) –A collection of source code lines.
-
(modules_collection¤ModulesCollection | None, default:None) –A collection of modules.
-
(allow_inspection¤bool, default:True) –Whether to allow inspecting modules when visiting them is not possible.
-
(force_inspection¤bool, default:False) –Whether to force using dynamic analysis when loading data.
-
(find_stubs_package¤bool, default:False) –Whether to search for stubs-only package. If both the package and its stubs are found, they'll be merged together. If only the stubs are found, they'll be used as the package itself.
-
(resolve_aliases¤bool, default:False) –Whether to resolve aliases.
-
(resolve_external¤bool | None, default:None) –Whether to try to load unspecified modules to resolve aliases. Default value (
None) means to load external modules only if they are the private sibling or the origin module (for example whenastimports from_ast). -
(resolve_implicit¤bool, default:False) –When false, only try to resolve an alias if it is explicitly exported.
Source code in src/griffe/_internal/loader.py
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 | |
Advanced API¤
GriffeLoader ¤
GriffeLoader(
*,
extensions: Extensions | None = None,
search_paths: Sequence[str | Path] | None = None,
docstring_parser: DocstringStyle | Parser | None = None,
docstring_options: DocstringOptions | None = None,
lines_collection: LinesCollection | None = None,
modules_collection: ModulesCollection | None = None,
allow_inspection: bool = True,
force_inspection: bool = False,
store_source: bool = True,
)
The Griffe loader, allowing to load data from modules.
Parameters:
-
(extensions¤Extensions | None, default:None) –The extensions to use.
-
(search_paths¤Sequence[str | Path] | None, default:None) –The paths to search into.
-
(docstring_parser¤DocstringStyle | Parser | None, default:None) –The docstring parser to use. By default, no parsing is done.
-
(docstring_options¤DocstringOptions | None, default:None) –Docstring parsing options.
-
(lines_collection¤LinesCollection | None, default:None) –A collection of source code lines.
-
(modules_collection¤ModulesCollection | None, default:None) –A collection of modules.
-
(allow_inspection¤bool, default:True) –Whether to allow inspecting modules when visiting them is not possible.
-
(store_source¤bool, default:True) –Whether to store code source in the lines collection.
- Guide User guide Manipulating APIs
- Reference Python API
Methods:
-
expand_exports–Expand exports: try to recursively expand all module exports (
__all__values). -
expand_wildcards–Expand wildcards: try to recursively expand all found wildcards.
-
load–Load an object as a Griffe object, given its Python or file path.
-
resolve_aliases–Resolve aliases.
-
resolve_module_aliases–Follow aliases: try to recursively resolve all found aliases.
-
stats–Compute some statistics.
Attributes:
-
allow_inspection(bool) –Whether to allow inspecting (importing) modules for which we can't find sources.
-
docstring_options(DocstringOptions) –Configured parsing options.
-
docstring_parser(DocstringStyle | Parser | None) –Selected docstring parser.
-
extensions(Extensions) –Loaded Griffe extensions.
-
finder(ModuleFinder) –The module source finder.
-
force_inspection(bool) –Whether to force inspecting (importing) modules, even when sources were found.
-
ignored_modules(set[str]) –Special modules to ignore when loading.
-
lines_collection(LinesCollection) –Collection of source code lines.
-
modules_collection(ModulesCollection) –Collection of modules.
-
store_source(bool) –Whether to store source code in the lines collection.
Source code in src/griffe/_internal/loader.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
allow_inspection instance-attribute ¤
allow_inspection: bool = allow_inspection
Whether to allow inspecting (importing) modules for which we can't find sources.
docstring_options instance-attribute ¤
docstring_options: DocstringOptions = (
docstring_options or {}
)
Configured parsing options.
docstring_parser instance-attribute ¤
docstring_parser: DocstringStyle | Parser | None = (
docstring_parser
)
Selected docstring parser.
extensions instance-attribute ¤
extensions: Extensions = extensions or load_extensions()
Loaded Griffe extensions.
force_inspection instance-attribute ¤
force_inspection: bool = force_inspection
Whether to force inspecting (importing) modules, even when sources were found.
ignored_modules class-attribute ¤
Special modules to ignore when loading.
For example, debugpy and _pydev are used when debugging with VSCode and should generally never be loaded.
lines_collection instance-attribute ¤
lines_collection: LinesCollection = (
lines_collection or LinesCollection()
)
Collection of source code lines.
modules_collection instance-attribute ¤
modules_collection: ModulesCollection = (
modules_collection or ModulesCollection()
)
Collection of modules.
store_source instance-attribute ¤
store_source: bool = store_source
Whether to store source code in the lines collection.
expand_exports ¤
Expand exports: try to recursively expand all module exports (__all__ values).
See also: Module.exports.
Parameters:
-
(module¤Module) –The module to recurse on.
-
(seen¤set | None, default:None) –Used to avoid infinite recursion.
Source code in src/griffe/_internal/loader.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
expand_wildcards ¤
Expand wildcards: try to recursively expand all found wildcards.
See also: Alias.wildcard.
Parameters:
-
(obj¤Object) –The object and its members to recurse on.
-
(external¤bool | None, default:None) –When true, try to load unspecified modules to expand wildcards.
-
(seen¤set | None, default:None) –Used to avoid infinite recursion.
Source code in src/griffe/_internal/loader.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
load ¤
load(
objspec: str | Path | None = None,
/,
*,
submodules: bool = True,
try_relative_path: bool = True,
find_stubs_package: bool = False,
) -> Object | Alias
Load an object as a Griffe object, given its Python or file path.
Note that this will load the whole object's package, and return only the specified object. The rest of the package can be accessed from the returned object with regular methods and properties (parent, members, etc.).
Examples:
>>> loader.load("griffe.Module")
Alias("Module", "griffe._internal.models.Module")
Parameters:
-
(objspec¤str | Path | None, default:None) –The Python path of an object, or file path to a module.
-
(submodules¤bool, default:True) –Whether to recurse on the submodules. This parameter only makes sense when loading a package (top-level module).
-
(try_relative_path¤bool, default:True) –Whether to try finding the module as a relative path.
-
(find_stubs_package¤bool, default:False) –Whether to search for stubs-only package. If both the package and its stubs are found, they'll be merged together. If only the stubs are found, they'll be used as the package itself.
Raises:
-
LoadingError–When loading a module failed for various reasons.
-
ModuleNotFoundError–When a module was not found and inspection is disallowed.
Returns:
- Guide User guide Manipulating APIs Loading APIs
Source code in src/griffe/_internal/loader.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
resolve_aliases ¤
resolve_aliases(
*,
implicit: bool = False,
external: bool | None = None,
max_iterations: int | None = None,
) -> tuple[set[str], int]
Resolve aliases.
Parameters:
-
(implicit¤bool, default:False) –When false, only try to resolve an alias if it is explicitly exported.
-
(external¤bool | None, default:None) –When false, don't try to load unspecified modules to resolve aliases.
-
(max_iterations¤int | None, default:None) –Maximum number of iterations on the loader modules collection.
Returns:
Source code in src/griffe/_internal/loader.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
resolve_module_aliases ¤
resolve_module_aliases(
obj: Object | Alias,
*,
implicit: bool = False,
external: bool | None = None,
seen: set[str] | None = None,
load_failures: set[str] | None = None,
) -> tuple[set[str], set[str]]
Follow aliases: try to recursively resolve all found aliases.
Parameters:
-
(obj¤Object | Alias) –The object and its members to recurse on.
-
(implicit¤bool, default:False) –When false, only try to resolve an alias if it is explicitly exported.
-
(external¤bool | None, default:None) –When false, don't try to load unspecified modules to resolve aliases.
-
(seen¤set[str] | None, default:None) –Used to avoid infinite recursion.
-
(load_failures¤set[str] | None, default:None) –Set of external packages we failed to load (to prevent retries).
Returns:
Source code in src/griffe/_internal/loader.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | |
stats ¤
stats() -> Stats
Compute some statistics.
Returns:
-
Stats–Some statistics.
Source code in src/griffe/_internal/loader.py
530 531 532 533 534 535 536 537 538 539 | |
ModulesCollection ¤
ModulesCollection()
Bases: GetMembersMixin, SetMembersMixin, DelMembersMixin
flowchart TD
griffe.ModulesCollection[ModulesCollection]
griffe._internal.mixins.GetMembersMixin[GetMembersMixin]
griffe._internal.mixins.SetMembersMixin[SetMembersMixin]
griffe._internal.mixins.DelMembersMixin[DelMembersMixin]
griffe._internal.mixins.GetMembersMixin --> griffe.ModulesCollection
griffe._internal.mixins.SetMembersMixin --> griffe.ModulesCollection
griffe._internal.mixins.DelMembersMixin --> griffe.ModulesCollection
click griffe.ModulesCollection href "" "griffe.ModulesCollection"
click griffe._internal.mixins.GetMembersMixin href "" "griffe._internal.mixins.GetMembersMixin"
click griffe._internal.mixins.SetMembersMixin href "" "griffe._internal.mixins.SetMembersMixin"
click griffe._internal.mixins.DelMembersMixin href "" "griffe._internal.mixins.DelMembersMixin"
A collection of modules, allowing easy access to members.
Initialize the collection.
- Guide User guide Manipulating APIs Loading APIs Alias resolution Modules collection
- Reference Python API Models
Aliasis_collection
Methods:
-
__bool__–A modules collection is always true-ish.
-
__contains__–Check if a module is in the collection.
-
__delitem__–Delete a member with its name or path.
-
__getitem__–Get a member with its name or path.
-
__setitem__–Set a member with its name or path.
-
del_member–Delete a member with its name or path.
-
get_member–Get a member with its name or path.
-
set_member–Set a member with its name or path.
Attributes:
-
all_members(dict[str, Module]) –Members of the collection.
-
is_collection–Marked as collection to distinguish from objects.
-
members(dict[str, Module]) –Members (modules) of the collection.
Source code in src/griffe/_internal/collections.py
71 72 73 74 | |
all_members property ¤
Members of the collection.
This property is overwritten to simply return self.members, as all_members does not make sense for a modules collection.
is_collection class-attribute instance-attribute ¤
is_collection = True
Marked as collection to distinguish from objects.
__bool__ ¤
__bool__() -> bool
A modules collection is always true-ish.
Source code in src/griffe/_internal/collections.py
76 77 78 | |
__contains__ ¤
Check if a module is in the collection.
Source code in src/griffe/_internal/collections.py
80 81 82 | |
__delitem__ ¤
Delete a member with its name or path.
This method is part of the consumer API: do not use when producing Griffe trees!
Members will be looked up in both declared members and inherited ones, triggering computation of the latter.
Parameters:
Examples:
>>> del griffe_object["foo"]
>>> del griffe_object["path.to.bar"]
>>> del griffe_object[("path", "to", "qux")]
Source code in src/griffe/_internal/mixins.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
__getitem__ ¤
Get a member with its name or path.
This method is part of the consumer API: do not use when producing Griffe trees!
Members will be looked up in both declared members and inherited ones, triggering computation of the latter.
Parameters:
Examples:
>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> qux = griffe_object[("path", "to", "qux")]
Source code in src/griffe/_internal/mixins.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
__setitem__ ¤
Set a member with its name or path.
This method is part of the consumer API: do not use when producing Griffe trees!
Parameters:
-
(key¤str | Sequence[str]) –The name or path of the member.
-
(value¤Object | Alias) –The member.
Examples:
>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux
Source code in src/griffe/_internal/mixins.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
del_member ¤
Delete a member with its name or path.
This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).
Members will be looked up in declared members only, not inherited ones.
Parameters:
Examples:
>>> griffe_object.del_member("foo")
>>> griffe_object.del_member("path.to.bar")
>>> griffe_object.del_member(("path", "to", "qux"))
Source code in src/griffe/_internal/mixins.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
get_member ¤
Get a member with its name or path.
This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).
Members will be looked up in declared members only, not inherited ones.
Parameters:
Examples:
>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> bar = griffe_object[("path", "to", "bar")]
Source code in src/griffe/_internal/mixins.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
set_member ¤
Set a member with its name or path.
This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).
Parameters:
-
(key¤str | Sequence[str]) –The name or path of the member.
-
(value¤Object | Alias) –The member.
Examples:
>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux"), qux)
Source code in src/griffe/_internal/mixins.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
LinesCollection ¤
LinesCollection()
A simple dictionary containing the modules source code lines.
Initialize the collection.
Methods:
-
__bool__–A lines collection is always true-ish.
-
__contains__–Check if a file path is in the collection.
-
__getitem__–Get the lines of a file path.
-
__setitem__–Set the lines of a file path.
-
items–Return the collection items.
-
keys–Return the collection keys.
-
values–Return the collection values.
Source code in src/griffe/_internal/collections.py
20 21 22 | |
__bool__ ¤
__bool__() -> bool
A lines collection is always true-ish.
Source code in src/griffe/_internal/collections.py
36 37 38 | |
__contains__ ¤
Check if a file path is in the collection.
Source code in src/griffe/_internal/collections.py
32 33 34 | |
__getitem__ ¤
Get the lines of a file path.
Source code in src/griffe/_internal/collections.py
24 25 26 | |
__setitem__ ¤
Set the lines of a file path.
Source code in src/griffe/_internal/collections.py
28 29 30 | |
items ¤
items() -> ItemsView
Return the collection items.
Returns:
-
ItemsView–The collection items.
Source code in src/griffe/_internal/collections.py
56 57 58 59 60 61 62 | |
keys ¤
keys() -> KeysView
Return the collection keys.
Returns:
-
KeysView–The collection keys.
Source code in src/griffe/_internal/collections.py
40 41 42 43 44 45 46 | |
values ¤
values() -> ValuesView
Return the collection values.
Returns:
-
ValuesView–The collection values.
Source code in src/griffe/_internal/collections.py
48 49 50 51 52 53 54 | |
Additional API¤
Stats ¤
Stats(loader: GriffeLoader)
Load statistics for a Griffe loader.
Parameters:
-
(loader¤GriffeLoader) –The loader to compute stats for.
Methods:
-
as_text–Format the statistics as text.
Attributes:
-
by_kind–Number of objects by kind.
-
lines–Total number of lines.
-
loader–The loader to compute stats for.
-
modules_by_extension–Number of modules by extension.
-
packages–Number of packages.
-
time_spent_inspecting–Time spent inspecting modules.
-
time_spent_serializing–Time spent serializing objects.
-
time_spent_visiting–Time spent visiting modules.
Source code in src/griffe/_internal/stats.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
by_kind instance-attribute ¤
by_kind = {
MODULE: 0,
CLASS: 0,
FUNCTION: 0,
ATTRIBUTE: 0,
TYPE_ALIAS: 0,
}
Number of objects by kind.
modules_by_extension instance-attribute ¤
modules_by_extension = modules_by_extension
Number of modules by extension.
time_spent_serializing instance-attribute ¤
time_spent_serializing = 0
Time spent serializing objects.
as_text ¤
as_text() -> str
Format the statistics as text.
Returns:
-
str–Text stats.
Source code in src/griffe/_internal/stats.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
merge_stubs ¤
Merge stubs into a module.
Parameters:
-
(mod1¤Module) –A regular module or stubs module.
-
(mod2¤Module) –A regular module or stubs module.
Raises:
-
ValueError–When both modules are regular modules (no stubs is passed).
Returns:
-
Module–The regular module.
Source code in src/griffe/_internal/merger.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |