Skip to content

Commit

Permalink
removed typeguard (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Maas authored Sep 4, 2022
1 parent b3bed87 commit 8c0a2b2
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 9 deletions.
9 changes: 1 addition & 8 deletions deptry/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Any, Dict, List, Optional

import toml
from typeguard import TypeCheckError, check_type

DEFAULTS = {"ignore_dependencies": None, "ignore_directories": [".venv"], "ignore_notebooks": False}

Expand Down Expand Up @@ -46,16 +45,10 @@ def _read_configuration_from_pyproject_toml(self) -> Optional[Dict]:

def _override_with_toml_argument(self, argument: str, expected_type: Any, pyproject_toml_config: Dict) -> None:
"""
If argument is found in pyproject.toml, check if it's the correct type and then override the default argument with the found value.
If argument is found in pyproject.toml, override the default argument with the found value.
"""
if argument in pyproject_toml_config:
value = pyproject_toml_config[argument]
try:
check_type(value, expected_type)
except TypeCheckError:
raise TypeCheckError(
f"Invalid argument supplied for `{argument}` in pyproject.toml. Should be {str(expected_type)}"
)
setattr(self, argument, value)
self._log_changed_by_pyproject_toml(argument, value)

Expand Down
138 changes: 138 additions & 0 deletions notebooks/Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "064f4445-752d-48e7-bbac-72fe198e28a2",
"metadata": {},
"outputs": [],
"source": [
"import ast"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6d2dda83-00d2-407a-87ff-b602b415cb5c",
"metadata": {},
"outputs": [],
"source": [
"root = ast.parse(\n",
"\"\"\"\n",
"x=1\n",
"import pandas as pd\n",
"from numpy import random\n",
"if x>0:\n",
" import click\n",
"elif x<0:\n",
" from typing import List\n",
"else:\n",
" import logging\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "00957720-c90a-47be-bb95-4e59dcc026d3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<ast.Module at 0x110524fd0>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"root"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "729215e5-abc3-4dae-98f7-96ab7c41727a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<ast.Assign object at 0x110524fa0>\n",
"<ast.Import object at 0x110524f10>\n",
"<ast.ImportFrom object at 0x110524e50>\n",
"<ast.If object at 0x110524e20>\n",
"<ast.Compare object at 0x110524be0>\n",
"<ast.ImportFrom object at 0x110524b20>\n",
"<ast.Import object at 0x1105249a0>\n"
]
}
],
"source": [
"for node in ast.iter_child_nodes(root):\n",
" print(node)\n",
" if isinstance(node, ast.If):\n",
" for node in ast.iter_child_nodes(node):\n",
" if isinstance(node, ast.If):\n",
" for node in ast.iter_child_nodes(node):\n",
" print(node)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "8f70351b-1852-4628-b683-db42be55e943",
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "'Module' object is not subscriptable",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Input \u001b[0;32mIn [6]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m node \u001b[38;5;129;01min\u001b[39;00m ast\u001b[38;5;241m.\u001b[39miter_child_nodes(\u001b[43mroot\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m]\u001b[49m):\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(node)\n",
"\u001b[0;31mTypeError\u001b[0m: 'Module' object is not subscriptable"
]
}
],
"source": [
"for node in ast.iter_child_nodes(root):\n",
" print(node)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d4978dbe-2173-404f-a46a-8839e09a4e52",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ python = ">=3.8,<3.11"
toml = "^0.10.2"
isort = "^5.10.1"
click = "^8.1.3"
typeguard = {git = "https://github.com/agronholm/typeguard.git", rev = "master"}

[tool.poetry.dev-dependencies]
black = "^22.6.0"
Expand Down

0 comments on commit 8c0a2b2

Please sign in to comment.